package com.hainatong.shiphelper.mainhome;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;

import com.base.common.view.base.BaseActivity;
import com.base.common.viewmodel.BaseViewModel;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.hainatong.shiphelper.R;
import com.hainatong.shiphelper.databinding.ActivityMainHomeBinding;
import com.hainatong.shiphelper.mainhome.adapter.HomeFragmentPagerAdapter;
import com.hainatong.shiphelper.mainhome.entity.TabEntity;
import com.hainatong.shiphelper.mainhome.fragment.MessageFragment;
import com.hainatong.shiphelper.mainhome.fragment.UserFragment;
import com.hainatong.shiphelper.mainhome.fragment.WelcomeFragment;
import com.hainatong.shiphelper.mainhome.fragment.WokePartFragment;
import com.hainatong.shiphelper.widget.FireManeuverDialog;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;


public class MainHomeActivity extends BaseActivity<ActivityMainHomeBinding, BaseViewModel> {

    public static void start(Context context) {
        context.startActivity(new Intent(context, MainHomeActivity.class));
        ((Activity) context).overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
    }

    /**
     * 切换语言 重启主页面
     *
     * @param context
     */
    public static void reStart(Context context) {
        Intent intent = new Intent(context, MainHomeActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }


    private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
    private List<Fragment> fragmentList;
    private HomeFragmentPagerAdapter vpAdapter;
    private FireManeuverDialog maneuverDialog;//广告弹窗

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_home);
    }

    @Override
    protected void initView()
    {
//        ImmersionBar.with(this).init();
        maneuverDialog = new FireManeuverDialog(this);


        mTabEntities.add(new TabEntity(getString(R.string.first_page_tag), R.mipmap.ic_tab_home_select, R.mipmap.ic_tab_home_unselect));
        mTabEntities.add(new TabEntity(getString(R.string.msg_page_tag), R.mipmap.ic_tab_msg_select, R.mipmap.ic_tab_msg_unselect));
        mTabEntities.add(new TabEntity(getString(R.string.work_page_tag), R.mipmap.ic_tab_msg_select, R.mipmap.ic_tab_msg_unselect));
        mTabEntities.add(new TabEntity(getString(R.string.me_page_tag), R.mipmap.ic_tab_me_select, R.mipmap.ic_tab_me_unselect));

        fragmentList = new ArrayList<>();
        fragmentList.add(new WelcomeFragment());
        fragmentList.add(new MessageFragment());
        fragmentList.add(new WokePartFragment());
        fragmentList.add(new UserFragment());


        vpAdapter = new HomeFragmentPagerAdapter(getSupportFragmentManager(), fragmentList);
        binding.vpHome.setAdapter(vpAdapter);
        binding.vpHome.setOffscreenPageLimit(3);

        binding.comTl.setTabData(mTabEntities);
        binding.comTl.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                binding.vpHome.setCurrentItem(position);

                // 设置状态栏为白底黑字
//                StatusBarUtils.setStatusBarDarkFont(MainHomeActivity.this, true);

                if (position == 2) {
                    //maneuverDialog.show();

                }
            }

            @Override
            public void onTabReselect(int position) {
            }
        });
        binding.vpHome.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                binding.comTl.setCurrentTab(position);

                // 设置状态栏为白底黑字
//                StatusBarUtils.setStatusBarDarkFont(MainHomeActivity.this, true);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }




    @Override
    protected void initData()
    {
        // 显示 消息提示 的红点
        //binding.comTl.showMsg(1, 0);
    }




}
